package com.aclass.wang.c206;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class Main2Activity extends AppCompatActivity {

    private String selectText;
    private View.OnClickListener listener;

    public Main2Activity() {
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        final RadioGroup rgFood = (RadioGroup) findViewById(R.id.rg_food);
        Button btn = (Button) findViewById(R.id.btn_test);
        final ImageView imageView = (ImageView) findViewById(R.id.imageView);
        btn.setOnClickListener(listener);

        rgFood.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton button = (RadioButton) findViewById(rgFood.getCheckedRadioButtonId());
                selectText = button.getText().toString();
                Toast.makeText(Main2Activity.this, "你选择了:" + selectText,
                        Toast.LENGTH_SHORT).show();
                if (rgFood.getCheckedRadioButtonId()==R.id.rb_niurou) {
                    imageView.setImageResource(R.drawable.beef);
                };
                if (rgFood.getCheckedRadioButtonId()==R.id.rb_haixina) {
                    imageView.setImageResource(R.drawable.seafood);
                };
                if (rgFood.getCheckedRadioButtonId()==R.id.rb_kaorou) {
                    imageView.setImageResource(R.drawable.barbecue);
                };
            }
        });


        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(Main2Activity.this, "你提交了:" + selectText,
                        Toast.LENGTH_SHORT).show();
            }
        });


    }
}
